package cn.tedu._06interceptor.base.config;

import cn.tedu._06interceptor.base.interceptors.MyInterceptor1;
import cn.tedu._06interceptor.base.interceptors.MyInterceptor2;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Author Justin Parker
 * @Date 2024/8/14 0014 11:18
 * @Version 1.0
 */

/**
 * WebMvcConfigurer接口:Spring MVC的标准化配置接口;
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //1.注册拦截器【指定拦截策略】
        //策略1：拦截所有请求
        //registry.addInterceptor(new MyInterceptor1());

        //策略2.指定拦截器【指定拦截路径】
        //registry.addInterceptor(new MyInterceptor1()).addPathPatterns("/v1/users/reg","/v1/users/login");

        //策略3.拦截指定的请求，比如拦截用户模块的所有请求；
        //registry.addInterceptor(new MyInterceptor1()).addPathPatterns("/v1/users/**");

        //策略4.排除指定的请求，比如拦截用户模块除了登录模块的所有请求；
//        registry.addInterceptor(new MyInterceptor1())
//                .addPathPatterns("/v1/users/**")
//                .excludePathPatterns("/v1/users/login");
//
//        registry.addInterceptor(new MyInterceptor1()).addPathPatterns("/v1/users/login");

        //注册多个拦截器
        registry.addInterceptor(new MyInterceptor1());
        registry.addInterceptor(new MyInterceptor2());
    }


}
